using UnityEngine;
using System.Collections;

public class SeguirPontos : MonoBehaviour {
	
	public GameObject[] pontos = new GameObject[4];
	public float vel;
	private int i = 0;
	private bool x;
	private bool z;
	
	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(i < 4)
		{
			if(x == false && z == false)
			{
				if(transform.position.x != pontos[i].transform.position.x && transform.position.z != pontos[i].transform.position.z)
				{
					transform.LookAt(new Vector3(pontos[i].transform.position.x, transform.position.y, pontos[i].transform.position.z));
				}
			}
			else
			{
				i++;
				z = false;
				x = false;
			}
			
			if(transform.position.x == pontos[i].transform.position.x)
			{
				x = true;
				transform.LookAt(new Vector3(transform.position.x, transform.position.y, pontos[i].transform.position.z));
			}
			
			if(transform.position.z == pontos[i].transform.position.z)
			{
				z = true;
				transform.LookAt(new Vector3(pontos[i].transform.position.x, transform.position.y, transform.position.z));
			}
			
			transform.Translate(0,0,vel);
		}
	}
}
